
<template>
    <div class="port-page">
        <!-- 顶部按钮 -->
        <div class="but1">
        <router-link to="/home">
         	<el-button type="warning" size="small" class="add btn" style='margin-right: 5px;' @click="cancelf" icon="el-icon-menu">首页</el-button>
        </router-link>
        <el-button type="success"   size="small" class="add btn" style=' margin-top:10px;margin-right: 10px;' @click='componentsShow("add")' icon="el-icon-edit">添加</el-button>
        </div>
        <!-- 模糊搜索条件 -->
        <div class="search">
        	<el-button type="text" size="small" class="add btn" style=' text-decoration:underline;' v-if="ss" @click='gd'>更多</el-button>
            <el-button type="text" size="small" class="add btn" style=' text-decoration:underline;' v-if="ss1" @click='gd1'>更多</el-button>
        	<div class="search-item">
        		<span>状态</span>
        		<el-select v-model="visqy" @change="search" class="code-search" style='width: 10px;'>
                	<el-option label="所有" value=""></el-option>
                    <el-option label="在职" value="Y"></el-option>
                    <el-option label="离职" value="N"></el-option>
                </el-select>
     	    </div>
            <div class="search-item">
                <el-input placeholder="请输入姓名查询" class="code-search" v-model="vkeyword"  @keyup.enter.native="search" icon="search"></el-input>
            </div>
            <el-button type="primary" class="add btn" style="border-radius:13px;" :loading="searchLoading" @click="search" icon="el-icon-search"></el-button>
            <!--下拉框  固定  -->
        </div>
        
        <div class="search1" v-if='aa'>
            <span>人事职位</span>
        	<div class="search-item">
		    <el-select v-model="vlstype" class="code-search" @change="search()" >
					<el-option :label="v.mc" :value="v.code" v-for="v in comboxlist"></el-option>
		    </el-select>
 			</div>
        </div>
        <!-- 数据表格展示区域 -->
        <el-table
            :data="dataList"
            border
            stripe
            align="left"
            size="small"
            class="admin-table"
            @select="checkSelect"
            :default-sort = "{prop: 'date', order: 'descending'}"
            @select-all="checkall">
            <!--<el-table-column type="selection" width="55"></el-table-column>-->
            <el-table-column label="中文名" width="100" align="center">
				<template scope="scope">
					<el-button size="mini" type="text" style="color:#1F2D3D;text-decoration:underline;background: #BEDBDF;" @click="componentsShow('lsxq',scope)">{{scope.row.zwm}}</el-button>
					<!--<el-button size="mini" type="text" v-else='scope.row.lstype!="老师"' style="color:#1F2D3D" >{{scope.row.zwm}}</el-button>-->
				</template>
			</el-table-column>
            <div slot='empty'>
                <img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
                <span style="vertical-align: middle;">暂时还没有内容哦!</span>
            </div>
            <el-table-column
                :prop="v.prop"
                :label="v.label"
                v-for="(v,index) in portTitleList"
                align="center"
                show-overflow-tooltip
                v-if="v.hide != 0"
                :formatter="v.formatter"
                :align="v.align || 'center'"
                :fixed="v.fixed"
                :class-name="v.columnStyle"
                :width="v.width"
                :min-width="v.minWidth"
                :header-align="v.headerAlign || 'center'"
                >
                <template scope="scope">
                    <div slot="reference" :style="tableCellControl(scope)">
                        {{ scope.row[scope.column.property] }}
                    </div>
                 </template>
            </el-table-column>
            <el-table-column  fixed="right" align="center"  label="操作"  width="180px">
                <template scope="scope">
                     <el-button size="mini"  type="warning" @click="componentsShow('edit',scope)">编辑</el-button>
                     <el-dropdown>
	                     <el-button type="primary" size="mini"> 更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
						 <el-dropdown-menu slot="dropdown">
						    <el-dropdown-item><el-button size="mini"  type="primary"  v-if='scope.row.isqymc=="在职"' @click="componentsShow('czmm',scope)">重置密码</el-button></el-dropdown-item>
						    <el-dropdown-item><el-button size="mini"  type="warning" v-if='scope.row.isqymc=="在职"' @click="componentsShow('authority',scope)">修改权限</el-button></el-dropdown-item>
						    <el-dropdown-item><el-button size="mini"  type="danger"  @click="componentsShow('singleDelete',scope)">删----除</el-button></el-dropdown-item>
						 </el-dropdown-menu>
					 </el-dropdown>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页查询区域 -->
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="pageindex"
            :page-sizes="pagesizes"
            :page-size="pagesize"
            :layout="layout"
            :total="total"
            class="class-page">
        </el-pagination>
        <!-- 各个组件显示区域 -->
        <!-- 动画加载 -->
        <LoadingComponent v-show="isLoading"></LoadingComponent>
        <!-- 添加组件 -->
        <AddComponent v-if="portComponents.add.toggle" @close="componentsHide" :params="this.vlstype"></AddComponent>
        <!-- 编辑组件 -->
        <EditComponent v-if="portComponents.edit.toggle" @close="componentsHide" :params="portComponents.edit.params"></EditComponent>
        <CzmmComponent v-if="portComponents.czmm.toggle" @close="componentsHide" :params="portComponents.czmm.params"></CzmmComponent>
        <LsxqComponent v-if="portComponents.lsxq.toggle" @close="componentsHide" :params="portComponents.lsxq.params"></LsxqComponent>
        <!-- info组件 -->
        <infoComponent v-if="portComponents.info.toggle" @close="componentsHide" :params="portComponents.info.params"></infoComponent>
        <!-- 单独删除组件 -->
        <DeleteComponent v-if="portComponents.singleDelete.toggle"  @close="componentsHide"  :data="portComponents.singleDelete.data"></DeleteComponent>
        <!-- 批量删除组件 -->
        <DeleteComponent v-if="portComponents.multipleDelete.toggle"  @close="componentsHide"  :data="portComponents.multipleDelete.data"></DeleteComponent>
        <!--权限组件-->
        <AuthorityComponent v-if="portComponents.authority.toggle"  @close="componentsHide"  :params="portComponents.authority.params"></AuthorityComponent>
        <!-- 子路由显示区域 -->
        <router-view class="port-view"></router-view>
    </div>
</template>
<script>
    import { mapState } from 'vuex'
    import qs from 'qs'
    import LoadingComponent from 'components/loading'
    import AddComponent from './add'
    import CzmmComponent from './czmm'
    import EditComponent from './edit'
    import InfoComponent from './info'
    import LsxqComponent from './lsxq'
    import DeleteComponent from './del'
    import AuthorityComponent from './authority'
    export default {
        components: { LoadingComponent, DeleteComponent,LsxqComponent, AddComponent, EditComponent,InfoComponent,AuthorityComponent ,CzmmComponent},
        data () {
            return {
            	aa:false,
			    ss:true,
			    ss1:false,
                qxbtn:{
					//人事信息设置
//					frmrsedityn:false,
//					frmrssqyn:false,
//					frmrsczmmyn:false,
				},
            /*模糊搜索条件*/
                vkeyword:'', // keyword
                vlstype:'',
                visqy:'Y',
                sx:'Y',
				multipleDelNum:'', //获取批量选择的数据
                dataList: [],  //表格数据
                comboxlist:[], //下拉框 动态的

				/*动画加载*/
                isLoading: true,//动画加载
                searchLoading: false,//搜索按钮触发按钮动画
                /*分页属性设置*/
                layout: 'total, sizes, prev, pager, next, jumper',//组件布局
			    pageindex: this.$store.state.pageindex,//当前分页页码
                pagesizes: this.$store.state.pagesizes,//显示个数的选择器选项
                pagesize: this.$store.state.pagesize,//每页显示条目数
                total: 0,//总条数

                /*组件区域*/
                portComponents: {
                    /* 单行删除  */
                    singleDelete: {
                        type: 'singleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'single',
                            title: '此操作将删除该记录?, 是否继续?'
                        }
                    },
                    /* 批量删除 */
                    multipleDelete: {
                        type: 'multipleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'multiple',
                            title: '此操作将删除您选中的记录?, 是否继续?'
                        }
                    },
                    /* 添加 */
                    add: {
                        type: 'add',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    /* 编辑 */
                    edit: {
                        type: 'edit',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    /* info */
                    info: {
                        type: 'info',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                     /*权限*/
                     authority: {
                        type: 'authority',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    czmm: {
                        type: 'czmm',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                     lsxq: {
                        type: 'lsxq',
                        toggle: false,
                        params: '',
                        data: {}
                    }
                },
                /*
                    prop :  接口参数名
                    label : 接口中文名
                    hide : 是否隐藏这一列
                    align : 这一列对齐顺序 ： left,right,center
                    headerAlign : 这一列表头对齐方式 ： left,right,center
                */
                portTitleList: [

                    {
                        prop:'id',
                        label:'编号',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'gh',
                        label:'工号',
                        hide:0,
                        align:'left',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'left',
                        formatter: function(row,column) {}
                    },
                     {
                        prop:'zwm',
                        label:'中文名',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'ywm',
                        label:'英文名',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'xzlsmc',
                        label:'行政老师',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'mm',
                        label:'密码',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'xb',
                        label:'性别',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'60',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'dh',
                        label:'电话',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'110',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'tx',
                        label:'头像',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'xxid',
                        label:'学校ID',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'xxmc',
                        label:'学校名称',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'80',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'bjs',
                        label:'班级数',
                        hide:0,
                        align:'left',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'left',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'lstype',
                        label:'职位',
                        // (ls老师zj助教xz行政lsz教务主任cw财务xzz行政主任cw财务主任cap校长)
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'isqymc',
                        label:'在职状态',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'120',
                        headerAlign:'center',
                        formatter: function(row,column){}
//                      { cellValue='asdfasd' },

//                      	Function(row, column)
//                      render: (h, params) => {
//                          return h('div', [
//                              h('span', params.row.isqy=="Y"?"启用":"禁用")
//                          ]);
//                      }
                    },
                    {
                        prop:'zcsj',
                        label:'注册日期',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'130',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },

                    {
                        prop:'auth',
                        label:'权限',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },

                ]
            }
        },
        created () {
            var logininfo = JSON.parse(localStorage.logininfo) ;
            this.$store.dispatch('changeTitle','人事管理');//修改title
            this.$store.dispatch('changeRouterIndex','/admin/person');//修改路由
            this.search();//分页获取默认数据
            this.getcomlist(); //加载下拉列表
            this.isLoading = true;//动画开始
        },
        mounted () {
            //加载完成之后event
            this.isLoading = false;//动画结束
        },
        methods: {
        	gd(){
        		this.aa=true;
        		this.ss=false;
        		this.ss1=true;
        	},
        	gd1(){
        		this.aa=false;
        		this.ss=true;
        		this.ss1=false;
        	},
//      	 search(type, scope) {
//				scope.row.isqy = type;
//				if (type=="Y")
//					scope.row.isqy="启用"
//				else if (type=="N")
//					scope.row.isqy="禁用"
//			},
  cancelf () {
          this.$store.dispatch('changeTitle','首页');//修改title
          // this.params.toggle = false;
//          this.$emit('close',{type:'time',cancel:true})
          },
          search () {
//        	空格处理
          	var vkeyword = this.vkeyword.replace(/^\s+|\s+$/g,"")
          	
          	var logininfo = JSON.parse(localStorage.logininfo);
              this.searchLoading = true;
             var params2 = qs.stringify({
                  isqy:this.visqy+'',
                      keyword: vkeyword, // keyword
                      lstype: this.vlstype,
                      yhid:logininfo.id,
                      xxid:logininfo.xxid,
                      pageindex: this.pageindex,
                      pagesize: this.pagesize
               })
             //执行
                 this.axios.post(this.$store.state.api + 'ls/list',  params2 )
                 .then(res => {
                  let data = res.data.data;
                  let list = data.list;
                  this.total = data.totalPage;
                  this.dataList = list;
                  this.searchLoading = false;
                 }).catch(res => {
                  this.searchLoading = false;
				})

          },
          getcomlist(){
				var logininfo = JSON.parse(localStorage.logininfo) ;
				var params3 = qs.stringify({
					yhid:logininfo.id,
					xxid:logininfo.xxid,
				});
					this.searchLoading = true;
					this.axios.post(this.$store.state.api + 'lstype/getlstypexlk',params3)
					.then( res => {
							let data = res.data.data;
							let list = data.list;
							this.comboxlist=list;
					}).catch( res => {
							this.searchLoading = false;
					})
			},
          tableCellControl (scope) {
            //表格单元格控制CSS样式
              /*  if (scope.row.id == 112 && scope.column.property == "iname") {
                    return {
                        color:"red",
                    }
                }else{
                    return {
                        color:"green",
                    }
                }*/
           },
           handleSizeChange (val) {//每页显示条数触发事件
                this.pagesize = val;
                this.pageindex = 1;
                this.search();
            },
            handleCurrentChange (val) {//分页触发事件
                this.search();
            },
            checkSelect (selection, row) {//点击单选select触发事件
                let strID = [];
                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                this.multipleDelNum = strID.join(",");
            },
            checkall (selection) {//点击全选select触发事件
                let strID = [];
                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                this.multipleDelNum = strID.join(",");
            },
            /* 组件的弹框  */
            componentsShow (type,data) { //显示组件
                for ( let i in this.portComponents ) {
                    if (type == this.portComponents[i].type) {
                        this.portComponents[i].toggle = true;
                        this.portComponents[i].params = data;
                        if (this.portComponents[i].data.type == 'single') {
                            this.portComponents[i].data.index = data.row.id
                        }else if(this.portComponents[i].data.type == 'multiple'){
                            this.portComponents[i].data.index = this.multipleDelNum;
                        }else{
                            return;
                        }
                        return;
                    }
                }
            },
            componentsHide (setting) { //关闭组件
                for ( let i in this.portComponents ) {
                    if (setting.type == this.portComponents[i].type) {
                        this.portComponents[i].toggle = false;
                        this.search();
                        if (!setting.cancel) {
                           this.search();
                        }
                        return;
                    }
                }
            }
        },
        computed: {
            ...mapState([
                'api'//域名
            ]),
            multipleDeleteDisabled () {
                if (this.multipleDelNum) {
                    return false;
                }else{
                    return true
                }
            }
        }
    }
</script>

<style lang="less" scoped>
    .port-page {
        font-size:12px;
        .btn {
            height: 30px;
            padding:0 10px;
            margin-left: 0;
        }
        .code-search {
            max-width: 130px;
            min-width: 100px;
            text-align: center;
            height: 50px;
            /*line-height: 50px;*/
            font-size: 12px;
        }
        .class-page {
            text-align: left;
            margin-top:10px;
        }
        .search-item {
            display: inline-block;
        }
        .but1{
			width: 23%;
			height: 50px;
			float: left;
			line-height: 50px;
		}
		.search{
			width: 77%;
			height: 50px;
			float: right;
			line-height: 50px;
			text-align: right;
		}
		.search1{
			width: 50%;
			height: 50px;
			float: right;
			line-height: 50px;
			margin-right: 142px;
			text-align: right;
		}
		.el-button+.el-button {
            margin-left: 2px;
            margin-top: 3px;
        }
    }
</style>
